package o;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
import com.google.android.gms.common.annotation.KeepForSdk;
import com.google.android.gms.common.internal.ShowFirstParty;
import com.google.android.gms.common.util.VisibleForTesting;
import java.util.concurrent.atomic.AtomicBoolean;
import o.aom.a;

@ShowFirstParty
@KeepForSdk
public class aol {
    @VisibleForTesting
    private static boolean ʻ = false;
    private static final AtomicBoolean ʼ = new AtomicBoolean();
    private static boolean ˊ = false;
    @KeepForSdk
    @Deprecated
    public static final int ˋ = 12451000;
    @VisibleForTesting
    private static boolean ˎ = false;
    @VisibleForTesting
    private static boolean ˏ = false;
    @KeepForSdk
    @VisibleForTesting
    static final AtomicBoolean ॱ = new AtomicBoolean();

    @KeepForSdk
    aol() {
    }

    @KeepForSdk
    @Deprecated
    public static int ˎ(Context context, int i) {
        try {
            context.getResources().getString(a.ˋ);
        } catch (Throwable th) {
            Log.e("GooglePlayServicesUtil", "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.");
        }
        if (!("com.google.android.gms".equals(context.getPackageName()) || ʼ.get())) {
            int ˊ = apl.ˊ(context);
            if (ˊ == 0) {
                throw new IllegalStateException("A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name=\"com.google.android.gms.version\" android:value=\"@integer/google_play_services_version\" />");
            } else if (ˊ != ˋ) {
                throw new IllegalStateException("The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected " + ˋ + " but found " + ˊ + ".  You must have the following declaration within the <application> element:     <meta-data android:name=\"com.google.android.gms.version\" android:value=\"@integer/google_play_services_version\" />");
            }
        }
        boolean z = (apq.ˋ(context) || apq.ˊ(context)) ? false : true;
        return ˊ(context, z, i);
    }

    @VisibleForTesting
    private static int ˊ(Context context, boolean z, int i) {
        apa.ˊ(i >= 0);
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = null;
        if (z) {
            try {
                packageInfo = packageManager.getPackageInfo("com.android.vending", 8256);
            } catch (NameNotFoundException e) {
                Log.w("GooglePlayServicesUtil", "Google Play Store is missing.");
                return 9;
            }
        }
        try {
            PackageInfo packageInfo2 = packageManager.getPackageInfo("com.google.android.gms", 64);
            aon.ˏ(context);
            if (!aon.ॱ(packageInfo2, true)) {
                Log.w("GooglePlayServicesUtil", "Google Play services signature invalid.");
                return 9;
            } else if (z && (!aon.ॱ(r0, true) || !r0.signatures[0].equals(packageInfo2.signatures[0]))) {
                Log.w("GooglePlayServicesUtil", "Google Play Store signature invalid.");
                return 9;
            } else if (apo.ॱ(packageInfo2.versionCode) < apo.ॱ(i)) {
                Log.w("GooglePlayServicesUtil", "Google Play services out of date.  Requires " + i + " but found " + packageInfo2.versionCode);
                return 2;
            } else {
                ApplicationInfo applicationInfo = packageInfo2.applicationInfo;
                if (applicationInfo == null) {
                    try {
                        applicationInfo = packageManager.getApplicationInfo("com.google.android.gms", 0);
                    } catch (Throwable e2) {
                        Log.wtf("GooglePlayServicesUtil", "Google Play services missing when getting application info.", e2);
                        return 1;
                    }
                }
                if (applicationInfo.enabled) {
                    return 0;
                }
                return 3;
            }
        } catch (NameNotFoundException e3) {
            Log.w("GooglePlayServicesUtil", "Google Play services is missing.");
            return 1;
        }
    }

    @ShowFirstParty
    @KeepForSdk
    @Deprecated
    public static boolean ॱ(Context context, int i) {
        if (i == 18) {
            return true;
        }
        if (i == 1) {
            return ˊ(context, "com.google.android.gms");
        }
        return false;
    }

    @TargetApi(21)
    static boolean ˊ(Context context, String str) {
        boolean equals = str.equals("com.google.android.gms");
        if (equals) {
        }
        if (app.ˎ()) {
            try {
                for (SessionInfo appPackageName : context.getPackageManager().getPackageInstaller().getAllSessions()) {
                    if (str.equals(appPackageName.getAppPackageName())) {
                        return true;
                    }
                }
            } catch (Exception e) {
                return false;
            }
        }
        try {
            ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(str, 8192);
            if (equals) {
                return applicationInfo.enabled;
            }
            return applicationInfo.enabled && !ˎ(context);
        } catch (NameNotFoundException e2) {
            return false;
        }
    }

    @TargetApi(18)
    @KeepForSdk
    public static boolean ˎ(Context context) {
        if (app.ॱ()) {
            Bundle applicationRestrictions = ((UserManager) context.getSystemService("user")).getApplicationRestrictions(context.getPackageName());
            if (applicationRestrictions != null && "true".equals(applicationRestrictions.getString("restricted_profile"))) {
                return true;
            }
        }
        return false;
    }
}
